package cn.doit.scala.day05.high_function

/**
 * @DATE 2021/12/30/11:17
 * @Author MDK
 * @Version 2021.2.2
 * */
object C01_高阶函数02 {
  def mkURL(ssl:Boolean, domain:String, k:String, v:String):String={
    if(ssl){
      s"https://$domain?$k=$v"
    }else{
      s"http://$domain?$k=$v"
    }
  }
  def mkUrl(ssl:Boolean, domain:String)={
    var port = "http"
    if(ssl){
      port="https"
    }
    val key = s"$port://$domain"
    //最后一行是返回值  方法返回值是函数
    (k:String, v:String)=>s"$key?$k=$v"
  }

  def main(args: Array[String]): Unit = {
    val f= mkUrl(true, domain = "www.doit.com")
    val res1 = f("username", "zss")
    val res2 = f("pwd", "123")
    val res3 = f("address", "bj")
    println(res1)
    println(res2)
    println(res3)

    val str1 = mkURL(true, "www.doit.com", "username", "zss")
    val str2 = mkURL(true, "www.doit.com", "pwd", "123")
    val str3 = mkURL(true, "www.doit.com", "address", "bj")
    println(str1)
    println(str2)
    println(str3)
  }
}
